<template>
  <view class="privacy" v-if="showPrivacy">
    <view class="content">
      <view class="title">隐私保护指引</view>
      <view class="des">
        在使用当前小程序服务之前，请仔细阅读
        <text class="link" @tap="openPrivacyContract">{{ privacyContractName }}</text>。
        如您同意{{ privacyContractName }}，请点击“同意”开始使用。
      </view>
      <view class="btns">
        <button class="item reject" @tap="close">拒绝</button>
        <button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    showPrivacy: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      privacyContractName: '《乐意小助手小程序隐私保护指引》'
    };
  },
  methods: {
    openPrivacyContract() {
      uni.openPrivacyContract();
    },
    close() {
      this.$emit('close');
    },
    handleAgreePrivacyAuthorization() {
      this.$emit('agree');
    }
  }
};
</script>

<style scoped>
.privacy {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.content {
  background: #fff;
  padding: 20px;
  border-radius: 10px;
  width: 80%;
  max-width: 300px; /* 限制最大宽度 */
}

.title {
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 10px;
}

.des {
  font-size: 14px;
  color: #666;
  margin-bottom: 20px;
}

.link {
  color: #07c160;
  text-decoration: underline;
}

.btns {
  display: flex;
  justify-content: space-between;
  gap: 10px; /* 按钮之间的间距 */
}

.item {
  flex: 1;
  padding: 12px 20px; /* 调整按钮内边距 */
  font-size: 16px; /* 调整字体大小 */
  text-align: center;
  border-radius: 8px; /* 调整圆角 */
  cursor: pointer;
  border: none; /* 移除默认边框 */
  outline: none; /* 移除默认轮廓 */
}

.reject {
  background: #f4f4f5;
  color: #909399;
}

.agree {
  background: #07c160;
  color: #fff;
}
</style>